package com.rran.study.chat.server.service.impl;

import com.rran.study.chat.server.cache.LocalCache;
import com.rran.study.chat.server.dto.request.AddMemberToGroupMsg;
import com.rran.study.chat.server.dto.request.CreateGroupMsg;
import com.rran.study.chat.server.dto.Response;
import com.rran.study.chat.server.service.GroupService;
import com.rran.study.chat.server.utils.RedisUtil;
import com.rran.study.chat.server.utils.UUIDUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yy
 * @Type UserServiceImpl.java
 * @Desc
 * @date 2020/8/9 18:58
 */
@Service
@Slf4j
public class GroupServiceImpl implements GroupService {

    @Autowired
    private RedisUtil redisUtil;


    @Override
    public Response createGroup(CreateGroupMsg msg) {
        String[] groupMembers = msg.getBeanIds();
        String groupId = UUIDUtil.getNumber(16);
        //缓存群组信息 todo by redis
        redisUtil.sAdd(groupId,groupMembers);
        return Response.success();
//        LocalCache.createGroup(groupId, groupMembers);
    }

    @Override
    public Response addMember(AddMemberToGroupMsg msg) {
        String[] beanIds = msg.getBeanIds();
        String groupId = msg.getGroupId();
        LocalCache.addMembers(groupId, beanIds);
        return Response.success();
    }
}
